﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Domaine.Entity
{
   public static class MembershipExtensions
    {

       public static System.Web.Security.MembershipUser ToMembershipUser(this Domaine.Entity.Membership member,string ProviderName="LMSMembershipProvider")
       {
           if (member == null) return null;
           return new System.Web.Security.MembershipUser(ProviderName, member.User.UserName,
                                        member.UserID, member.Email,
                                        member.PasswordQuestion,
                                        member.Comment, member.IsApproved,
                                        member.IsLockedOut, member.CreateDate,
                                        member.LastLoginDate, member.User.LastActivityDate,
                                        member.LastPasswordChangedDate, member.LastLockoutDate);
       }

      public static Domaine.Entity.Membership ToMember(this System.Web.Security.MembershipUser membershipUser){
          if (membershipUser == null) return null;

          return new Domaine.Entity.Membership()
          {
              User = new User()
              {
                  UserName = membershipUser.UserName,
                  LoweredUserName = membershipUser.UserName.ToLower(),
                  LastActivityDate = membershipUser.LastActivityDate,
                   
              },
              IsApproved=membershipUser.IsApproved,
              IsLockedOut=membershipUser.IsLockedOut,
              LastLockoutDate=membershipUser.LastLockoutDate,
              LastLoginDate=membershipUser.LastLoginDate,
              LastPasswordChangedDate=membershipUser.LastPasswordChangedDate,
              Email=membershipUser.Email,
              CreateDate = membershipUser.CreationDate,
              Comment = membershipUser.Comment,
              PasswordQuestion = membershipUser.PasswordQuestion,
          };

      }

    }
}
